package com.boot.controller;

import com.alibaba.fastjson.JSON;
import com.boot.entity.BaseResponse;
import com.boot.entity.TestEntity;
import com.boot.utils.OkHttpUtils;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Description: 用户控制层
 * @author: lh
 */
@RestController
@RequestMapping("/user")
public class UserController {

    AtomicInteger atomicIntegerForGet = new AtomicInteger();
    AtomicInteger atomicIntegerForPostJson = new AtomicInteger();
    AtomicInteger atomicIntegerForPostStr = new AtomicInteger();
    AtomicInteger atomicIntegerForPostForm = new AtomicInteger();
    AtomicInteger atomicInteger = new AtomicInteger();

    @GetMapping("/testGet")
    public String login(@RequestParam String uuid, @RequestParam String method)
    {
        BaseResponse response = new BaseResponse();
        atomicIntegerForGet.incrementAndGet();
        //System.out.println(uuid+method);
        if(!method.contains("testGet")){
            System.out.println("errorerror");
        }
        return uuid+method;
    }

    @PostMapping("testPostJson")
    public String testPostJson(@RequestBody TestEntity entity)
    {
        BaseResponse response = new BaseResponse();
        if (entity != null)
        {
            response.setCode(200);
            response.setMsg("用户注册成功");
        } else {
            response.setCode(500);
            response.setMsg("注册失败，请检查后重试");
        }
        if(!entity.getMethod().contains("testPostJson")){
            System.out.println("errorerror");
        }
        atomicIntegerForPostJson.incrementAndGet();
        // System.out.println(JSON.toJSONString(entity));
        return JSON.toJSONString(entity);
    }

    @PostMapping("testPostStr")
    public String testPostStr(@RequestBody String uuid)
    {
        BaseResponse response = new BaseResponse();
        if (uuid != null)
        {
            response.setCode(200);
            response.setMsg("用户注册成功");
        } else {
            response.setCode(500);
            response.setMsg("注册失败，请检查后重试");
        }
        if(!uuid.contains("testPostStr")){
            System.out.println("errorerror");
        }
        atomicIntegerForPostStr.incrementAndGet();
        //  System.out.println(uuid);
        return uuid;
    }

    @PostMapping("testPostForm")
    public String testPostForm( TestEntity user)
    {
        BaseResponse response = new BaseResponse();
        if (user != null)
        {
            response.setCode(200);
            response.setMsg("用户注册成功");
        } else {
            response.setCode(500);
            response.setMsg("注册失败，请检查后重试");
        }
        if(!user.getMethod().contains("testPostForm")){
            System.out.println("errorerror");
        }
        atomicIntegerForPostForm.incrementAndGet();

        return JSON.toJSONString(user);
    }
}